<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<header id="sss">
    <div class="lf">
        <a class="home" href="${pageContext.request.contextPath}/index">系统首页</a>
        <!-- <a href="bbs.html">论坛</a> -->
        <a href="${pageContext.request.contextPath}/res/upload">上传资源</a>
        <script src="${pageContext.request.contextPath}/js/vue.js"></script>
    </div>
    <div id="search">
        <input type="text" name="name"
               placeholder="请输入要搜索的资源" autocomplete="off" v-model="val" @keydown.enter="fSearch"/><a class="search btn" @click="fSearch">搜索</a>

    </div>

    <div class="rf">
        <c:if test="${empty sessionScope.local_session_user_flag}">
        <a href="${pageContext.request.contextPath}/user/login">登录/注册</a>
        </c:if>

        <div class="email-info">
            <b>{{announcementMsgList.length+notifiMsgList.length+unreadcount}}</b>
            <ul class="email-list" v-model="activeName">
                <li><a href="${pageContext.request.contextPath}/msg/message?f=official">官方<b>{{announcementMsgList.length}}</b></a></li>
                <li><a href="${pageContext.request.contextPath}/msg/message?f=inform">通知<b>{{notifiMsgList.length}}</b></a></li>
                <li><a href="${pageContext.request.contextPath}/msg/message?f=letter">私信<b>{{unreadcount}}</b></a></li>
            </ul>
        </div>

        <a class="info" href="${pageContext.request.contextPath}/user/personal">个人中心</a>
        <a class="cols" href="${pageContext.request.contextPath}/user/shoucang">收藏</a>
        <a class="exit" href="${pageContext.request.contextPath}/user/logout">退出登录</a>
    </div>


    <script>
        new Vue({
            el:"#sss",
            data:{
                val:"",
                announcementMsgList:[],
                notifiMsgList:[],
                totalMsg:'',
                unreadcount:0
            },
            created(){
                this.unread();
                this.notifiMessage();
                this.announcementMsg();
            },
            /*mounted(){
                this.notifiMessage();
                this.announcementMsg();
            },*/
            methods:{
                fSearch(){
                    window.location.href="${pageContext.request.contextPath}/index?Fname="+this.val;
                },
                unread(){
                    fetch("${pageContext.request.contextPath}/msg/unRead").then(ret=>{
                        if(ret.status){
                            this.unreadcount = ret.data;
                        }
                    })
                },
                /*加载官方通知消息*/
                announcementMsg(){
                    fetch("${pageContext.request.contextPath}/msg/announcement").then(ret =>{
                        this.announcementMsgList = ret.data;
                    })
                },
                /*加载通知消息*/
                notifiMessage(){
                    fetch("${pageContext.request.contextPath}/msg/notifi").then(ret =>{
                        if(ret.status){
                            this.notifiMsgList = ret.data;
                        }
                    })
                },

            }
        })
        /**
         * 实现被踢掉 提示的效果
         */
            <c:if test="${not empty sessionScope.local_session_user_flag}">

        let playing = setInterval(function() {
                fetch("${pageContext.request.contextPath}/check").catch(err => {
                    console.log("err",  err)
                    clearInterval(playing);
                });
            }, 2000)

        </c:if>

    </script>
</header>